var form = layui.form
form.verify({
    pass: [/^[\S]{6,12}$/, '密码必须6到12为,且不能有空格'],
    samepwd: function (val) {
        if (val === $('[name=oldPwd]').val()) {
            return '新旧密码不能相同！'
        }
    },
    repwd: function (val) {
        if (val !== $('[name=newPwd]').val()) {
            return '两次密码输入不一致'
        }
    }
})


$('.layui-form').on('submit', function (e) {
    e.preventDefault();
    $.ajax({
        method: 'post',
        url: '/my/updatepwd',
        data: $(this).serialize(),
        success: function (res) {
            console.log(res)
            if (res.status !== 0) {
                return layui.layer.msg('更新密码失败！')
            }
         
                layui.layer.msg('更新密码成功！')
                //重置表单
                $('.layui-form')[0].reset()
                sessionStorage.removeItem('token')
                window.parent.location.href = '/login.html'
        }
    })
})
